package com.newtouch.bxzs.policy.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.newtouch.bxzs.common.base.em.CompanyParameterTypeEnum;
import com.newtouch.bxzs.common.base.em.SystemParamsEnum;
import com.newtouch.bxzs.common.base.util.RedisUtils;
import com.newtouch.bxzs.common.base.util.SendHttpRequestUtils;
import com.newtouch.bxzs.policy.model.bo.PreservationBO;
import com.newtouch.bxzs.policy.model.bo.family.*;
import com.newtouch.bxzs.policy.model.vo.*;
import com.newtouch.bxzs.policy.model.vo.family.*;
import com.newtouch.bxzs.policy.service.FamilyPolicyInsuranceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 家庭单管理实现类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/7 13:33</td>
 * <td>linhongxi</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author linhongxi
 * @version 1.0.0
 * @since 1.0.0
 */
@Service
public class FamilyPolicyInsuranceServiceImpl implements FamilyPolicyInsuranceService {


    @Autowired
    private RedisUtils redisUtils;

    /**
     * 根据保单号查询家庭单详情信息
     * @param policyInfoVO 家庭单详情查询条件
     * @return 家庭单详情
     */
    @Override
    public FamilyPolicyBO getFamilyPolicyInfoInsurance(PolicyInfoVO policyInfoVO) {
        SendHttpRequestUtils<PolicyInfoVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(SystemParamsEnum.FAMILY_POLICY_INFO.getCode());
        return JSON.toJavaObject(sendHttpRequest.sendHttpRequestToJson(policyInfoVO, url),FamilyPolicyBO.class);
    }

    /**
     * 根据保单号获取保全列表
     *
     * @param policyInfoPageVO 家庭单详情--保全列表查询条件
     *
     * @return 家庭单详情--保全列表
     */
    @Override
    public List<PreservationBO> getFamilyPolicyPreservationInsurance(PolicyInfoPageVO policyInfoPageVO){
        SendHttpRequestUtils<PolicyInfoPageVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(SystemParamsEnum.FAMILY_POLICY_INFO_PRESERVATION.getCode());
        return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(policyInfoPageVO,url).toJSONString(),PreservationBO.class);

    }

    /**
     * 根据保单号获取理赔列表
     *
     * @param policyInfoPageVO 家庭单详情--理赔列表查询条件
     *
     * @return 家庭单详情--理赔列表
     */
    @Override
    public List<FamilyClaimsBO> getPolicyClaimsInsurance(PolicyInfoPageVO policyInfoPageVO){
        SendHttpRequestUtils<PolicyInfoPageVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(SystemParamsEnum.FAMILY_POLICY_INFO_CLAIMS.getCode());
        return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(policyInfoPageVO, url).toJSONString(),FamilyClaimsBO.class);
    }

    /**
     * 根据保单号获取家庭单人员清单列表
     *
     * @param policyUserListVO 家庭单详情--人员清单列表查询条件
     *
     * @return 家庭单详情--人员清单列表
     */
    @Override
    public List<PolicyUserListBO> getFamilyPolicyUserListInsurance(PolicyUserListVO policyUserListVO){
        SendHttpRequestUtils<PolicyUserListVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(SystemParamsEnum.FAMILY_POLICY_INFO_USER.getCode());
        return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(policyUserListVO, url).toJSONString(),PolicyUserListBO.class);
    }

    /**
     * 根据查询条件获取新契约进度列表
     *
     * @param familyPolicyNewContractVO 家庭单新契约进度列表查询条件
     *
     * @return 家庭单新契约进度列表
     */
    @Override
    public List<FamilyPolicyNewContractBO> getNewContractListByFamilyPolicyInsurance(FamilyPolicyNewContractVO familyPolicyNewContractVO){
        SendHttpRequestUtils<FamilyPolicyNewContractVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(SystemParamsEnum.FAMILY_POLICY_NEW_CONTRACT.getCode());
        return JSONArray.parseArray(sendHttpRequest.sendHttpRequestToArray(familyPolicyNewContractVO, url).toJSONString(),FamilyPolicyNewContractBO.class);
    }

    /**
     * 根据保单号获取新契约进度详情
     *
     * @param policyNewContractInfoVO 家庭单新契约进度详情查询条件
     *
     * @return 家庭单新契约进度详情
     */
    @Override
    public FamilyPolicyNewContractBO getNewContractInfoByFamilyPolicyInsurance(PolicyNewContractInfoVO policyNewContractInfoVO){
        SendHttpRequestUtils<PolicyNewContractInfoVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(SystemParamsEnum.FAMILY_POLICY_NEW_CONTRACT_INFO.getCode());
        return JSON.toJavaObject(sendHttpRequest.sendHttpRequestToJson(policyNewContractInfoVO, url),FamilyPolicyNewContractBO.class);
    }
    /**
     * 根据保单号获取家庭单新契约详情人员清单列表
     *
     * @param familyPolicyNewContractInfoVO 家庭单新契约进度详情--人员清单列表查询条件
     *
     * @return 家庭单新契约进度详情--人员清单列表
     */
    @Override
    public List<PolicyUserListBO> getNewContractUserListByFamilyPolicyInsurance(FamilyPolicyNewContractInfoVO familyPolicyNewContractInfoVO){
        SendHttpRequestUtils<FamilyPolicyNewContractInfoVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(SystemParamsEnum.FAMILY_POLICY_NEW_CONTRACT_INFO_USER.getCode());
        return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(familyPolicyNewContractInfoVO, url).toJSONString(),PolicyUserListBO.class);

    }

    /**
     * 根据查询条件获取保全进度列表
     *
     * @param familyPreservationVO 家庭单保全进度列表查询条件
     *
     * @return 家庭单保全进度列表
     */
    @Override
    public List<FamilyPreservationProgressInfoBO> getPreservationListByFamilyPolicyInsurance(FamilyPreservationVO familyPreservationVO){
        SendHttpRequestUtils<FamilyPreservationVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(SystemParamsEnum.FAMILY_POLICY_PRESERVATION.getCode());
        return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(familyPreservationVO, url).toJSONString(),FamilyPreservationProgressInfoBO.class);

    }
    /**
     * 根据保单号获取保全进度详情
     *
     * @param preservationProgressInfoVO 家庭单保全进度详情查询条件
     *
     * @return 家庭单保全进度详情
     */
    @Override
    public FamilyPreservationProgressInfoBO getPreservationInfoByFamilyPolicyInsurance(PreservationProgressInfoVO preservationProgressInfoVO){
        SendHttpRequestUtils<PreservationProgressInfoVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(CompanyParameterTypeEnum.FAMILY_POLICY_PRESERVATION_INFO.getCode());
        return JSON.toJavaObject(sendHttpRequest.sendHttpRequestToJson(preservationProgressInfoVO, url),FamilyPreservationProgressInfoBO.class);

    }

    /**
     * 根据查询条件获取理赔进度列表
     *
     * @param familyClaimsVO 家庭单理赔进度列表查询条件
     *
     * @return 家庭单理赔进度列表
     */
    @Override
    public List<FamilyClaimsBO> getClaimsProgressListByFamilyPolicyInsurance(FamilyClaimsVO familyClaimsVO){
        SendHttpRequestUtils<FamilyClaimsVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(CompanyParameterTypeEnum.FAMILY_POLICY_CLAIMS.getCode());
        return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(familyClaimsVO, url).toJSONString(),FamilyClaimsBO.class);
    }

    /**
     * 根据查询条件获取满期保单列表
     *
     * @param familyExpirationPolicyVO 家庭单满期列表查询条件
     *
     * @return 家庭单满期列表
     */
    @Override
    public List<FamilyExpirationPolicyBO> getExpirationPolicyListByFamilyPolicyInsurance(FamilyExpirationPolicyVO familyExpirationPolicyVO){
        SendHttpRequestUtils<FamilyExpirationPolicyVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(CompanyParameterTypeEnum.FAMILY_POLICY_EXPIRATION.getCode());
        return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(familyExpirationPolicyVO, url).toJSONString(),FamilyExpirationPolicyBO.class);
    }

    /**
     * 根据查询条件获取续期保单列表
     *
     * @param familyRenewalPolicyVO 家庭单续期列表查询条件
     *
     * @return 家庭单续期列表
     */
    @Override
    public List<FamilyRenewalPolicyBO> getRenewalPolicyListByFamilyPolicyInsurance(FamilyRenewalPolicyVO familyRenewalPolicyVO){

        SendHttpRequestUtils<FamilyRenewalPolicyVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(CompanyParameterTypeEnum.FAMILY_POLICY_RENEWAL.getCode());
        return  JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(familyRenewalPolicyVO, url).toJSONString(),FamilyRenewalPolicyBO.class);

    }

}
